package com.cloudm.technician.ui.modules.cloudm_box.machine_list

import com.cloudm.technician.data.model.DeviceInfo
import com.cloudm.technician.data.network.CloudmBoxApi
import com.cloudm.technician.ui.base.RxPresenter

/**
 * 作者: wesley
 * 时间: 2017/12/18
 * 描述: 机器列表的业务逻辑
 */
class MachineListPresenter(private val view: MachineListContract.View,
                           private val cloudmBoxApi: CloudmBoxApi) : RxPresenter(),
        MachineListContract.Presenter {

    override fun getMachineListInfo(page: Int, size: Int) {
        request(cloudmBoxApi.getMachineListInfo(page, size), view,
                onSuccess = { list, loadMoreInfo ->
                    view.loadSuccess(list, loadMoreInfo)
                }, onFailure = { errorMsg ->
            view.loadFailure(errorMsg)
        })
    }

    override fun deleteDevice(id: Int) {
        request(cloudmBoxApi.deleteDevice(id), view, onSuccess = { _, _ ->
            view.deleteSuccess()
        }, onFailure = { errorMsg ->
            view.deleteFailure(errorMsg)
        })
    }

    override fun openActivityByStatus(flag: Int, info: DeviceInfo) {
        when (info.status) {
            8, 9 -> view.showDoneStatusMsg()
            else -> view.openDeviceDetailActivity(flag, info)
        }
    }
}